{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3: Beginning Data Analysis\n",
    "\n",
    "## Recipes\n",
    "* [Developing a data analysis routine](#Developing-a-data-analysis-routine)\n",
    "* [Reducing memory by changing data types](#Reducing-memory-by-changing-data-types)\n",
    "* [Selecting the smallest of the largest](#Selecting-the-smallest-of-the-largest)\n",
    "* [Selecting the largest of each group by sorting](#Selecting-the-largest-of-each-group-by-sorting)\n",
    "* [Replicating nlargest with sort_values](#Replicating-nlargest-with-sort_values)\n",
    "* [Calculating a trailing stop order price](#Calculating-a-trailing-stop-order-price)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from IPython.display import display\n",
    "pd.options.display.max_columns = 50"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Developing a data analysis routine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "college = pd.read_csv('data/college.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>INSTNM</th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alabama A &amp; M University</td>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>424.0</td>\n",
       "      <td>420.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4206.0</td>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "      <td>0.0656</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7356</td>\n",
       "      <td>0.8284</td>\n",
       "      <td>0.1049</td>\n",
       "      <td>30300</td>\n",
       "      <td>33888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>University of Alabama at Birmingham</td>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>570.0</td>\n",
       "      <td>565.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11383.0</td>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "      <td>0.2607</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3460</td>\n",
       "      <td>0.5214</td>\n",
       "      <td>0.2422</td>\n",
       "      <td>39700</td>\n",
       "      <td>21941.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Amridge University</td>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>291.0</td>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "      <td>0.4536</td>\n",
       "      <td>1</td>\n",
       "      <td>0.6801</td>\n",
       "      <td>0.7795</td>\n",
       "      <td>0.8540</td>\n",
       "      <td>40100</td>\n",
       "      <td>23370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>University of Alabama in Huntsville</td>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Alabama State University</td>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>425.0</td>\n",
       "      <td>430.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4811.0</td>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "      <td>0.0892</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7347</td>\n",
       "      <td>0.7554</td>\n",
       "      <td>0.1270</td>\n",
       "      <td>26600</td>\n",
       "      <td>33118.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                INSTNM        CITY STABBR  HBCU  MENONLY  \\\n",
       "0             Alabama A & M University      Normal     AL   1.0      0.0   \n",
       "1  University of Alabama at Birmingham  Birmingham     AL   0.0      0.0   \n",
       "2                   Amridge University  Montgomery     AL   0.0      0.0   \n",
       "3  University of Alabama in Huntsville  Huntsville     AL   0.0      0.0   \n",
       "4             Alabama State University  Montgomery     AL   1.0      0.0   \n",
       "\n",
       "   WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  DISTANCEONLY     UGDS  UGDS_WHITE  \\\n",
       "0        0.0         0     424.0     420.0           0.0   4206.0      0.0333   \n",
       "1        0.0         0     570.0     565.0           0.0  11383.0      0.5922   \n",
       "2        0.0         1       NaN       NaN           1.0    291.0      0.2990   \n",
       "3        0.0         0     595.0     590.0           0.0   5451.0      0.6988   \n",
       "4        0.0         0     425.0     430.0           0.0   4811.0      0.0158   \n",
       "\n",
       "   UGDS_BLACK  UGDS_HISP  UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  UGDS_2MOR  \\\n",
       "0      0.9353     0.0055      0.0019     0.0024     0.0019     0.0000   \n",
       "1      0.2600     0.0283      0.0518     0.0022     0.0007     0.0368   \n",
       "2      0.4192     0.0069      0.0034     0.0000     0.0000     0.0000   \n",
       "3      0.1255     0.0382      0.0376     0.0143     0.0002     0.0172   \n",
       "4      0.9208     0.0121      0.0019     0.0010     0.0006     0.0098   \n",
       "\n",
       "   UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "0    0.0059     0.0138    0.0656         1   0.7356    0.8284   0.1049   \n",
       "1    0.0179     0.0100    0.2607         1   0.3460    0.5214   0.2422   \n",
       "2    0.0000     0.2715    0.4536         1   0.6801    0.7795   0.8540   \n",
       "3    0.0332     0.0350    0.2146         1   0.3072    0.4596   0.2640   \n",
       "4    0.0243     0.0137    0.0892         1   0.7347    0.7554   0.1270   \n",
       "\n",
       "  MD_EARN_WNE_P10 GRAD_DEBT_MDN_SUPP  \n",
       "0           30300              33888  \n",
       "1           39700            21941.5  \n",
       "2           40100              23370  \n",
       "3           45500              24097  \n",
       "4           26600            33118.5  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(7535, 27)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RELAFFIL</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.190975</td>\n",
       "      <td>0.393096</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.923291</td>\n",
       "      <td>0.266146</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.3578</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.3329</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2415</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            count      mean       std  min     25%      50%       75%  max\n",
       "HBCU       7164.0  0.014238  0.118478  0.0  0.0000  0.00000  0.000000  1.0\n",
       "MENONLY    7164.0  0.009213  0.095546  0.0  0.0000  0.00000  0.000000  1.0\n",
       "WOMENONLY  7164.0  0.005304  0.072642  0.0  0.0000  0.00000  0.000000  1.0\n",
       "RELAFFIL   7535.0  0.190975  0.393096  0.0  0.0000  0.00000  0.000000  1.0\n",
       "...           ...       ...       ...  ...     ...      ...       ...  ...\n",
       "CURROPER   7535.0  0.923291  0.266146  0.0  1.0000  1.00000  1.000000  1.0\n",
       "PCTPELL    6849.0  0.530643  0.225544  0.0  0.3578  0.52150  0.712900  1.0\n",
       "PCTFLOAN   6849.0  0.522211  0.283616  0.0  0.3329  0.58330  0.745000  1.0\n",
       "UG25ABV    6718.0  0.410021  0.228939  0.0  0.2415  0.40075  0.572275  1.0\n",
       "\n",
       "[22 rows x 8 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with pd.option_context('display.max_rows', 8):\n",
    "    display(college.describe(include=[np.number]).T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>unique</th>\n",
       "      <th>top</th>\n",
       "      <th>freq</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <td>7535</td>\n",
       "      <td>7535</td>\n",
       "      <td>San Francisco State University</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CITY</th>\n",
       "      <td>7535</td>\n",
       "      <td>2514</td>\n",
       "      <td>New York</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>STABBR</th>\n",
       "      <td>7535</td>\n",
       "      <td>59</td>\n",
       "      <td>CA</td>\n",
       "      <td>773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <td>6413</td>\n",
       "      <td>598</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "      <td>7503</td>\n",
       "      <td>2038</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>1510</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   count unique                             top  freq\n",
       "INSTNM              7535   7535  San Francisco State University     1\n",
       "CITY                7535   2514                        New York    87\n",
       "STABBR              7535     59                              CA   773\n",
       "MD_EARN_WNE_P10     6413    598               PrivacySuppressed   822\n",
       "GRAD_DEBT_MDN_SUPP  7503   2038               PrivacySuppressed  1510"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=[np.object, pd.Categorical]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 7535 entries, 0 to 7534\n",
      "Data columns (total 27 columns):\n",
      "INSTNM                7535 non-null object\n",
      "CITY                  7535 non-null object\n",
      "STABBR                7535 non-null object\n",
      "HBCU                  7164 non-null float64\n",
      "MENONLY               7164 non-null float64\n",
      "WOMENONLY             7164 non-null float64\n",
      "RELAFFIL              7535 non-null int64\n",
      "SATVRMID              1185 non-null float64\n",
      "SATMTMID              1196 non-null float64\n",
      "DISTANCEONLY          7164 non-null float64\n",
      "UGDS                  6874 non-null float64\n",
      "UGDS_WHITE            6874 non-null float64\n",
      "UGDS_BLACK            6874 non-null float64\n",
      "UGDS_HISP             6874 non-null float64\n",
      "UGDS_ASIAN            6874 non-null float64\n",
      "UGDS_AIAN             6874 non-null float64\n",
      "UGDS_NHPI             6874 non-null float64\n",
      "UGDS_2MOR             6874 non-null float64\n",
      "UGDS_NRA              6874 non-null float64\n",
      "UGDS_UNKN             6874 non-null float64\n",
      "PPTUG_EF              6853 non-null float64\n",
      "CURROPER              7535 non-null int64\n",
      "PCTPELL               6849 non-null float64\n",
      "PCTFLOAN              6849 non-null float64\n",
      "UG25ABV               6718 non-null float64\n",
      "MD_EARN_WNE_P10       6413 non-null object\n",
      "GRAD_DEBT_MDN_SUPP    7503 non-null object\n",
      "dtypes: float64(20), int64(2), object(5)\n",
      "memory usage: 1.6+ MB\n"
     ]
    }
   ],
   "source": [
    "college.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RELAFFIL</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.190975</td>\n",
       "      <td>0.393096</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATVRMID</th>\n",
       "      <td>1185.0</td>\n",
       "      <td>522.819409</td>\n",
       "      <td>68.578862</td>\n",
       "      <td>290.0</td>\n",
       "      <td>475.000000</td>\n",
       "      <td>510.00000</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>765.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATMTMID</th>\n",
       "      <td>1196.0</td>\n",
       "      <td>530.765050</td>\n",
       "      <td>73.469767</td>\n",
       "      <td>310.0</td>\n",
       "      <td>482.000000</td>\n",
       "      <td>520.00000</td>\n",
       "      <td>565.000000</td>\n",
       "      <td>785.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005583</td>\n",
       "      <td>0.074519</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>2356.837940</td>\n",
       "      <td>5474.275871</td>\n",
       "      <td>0.0</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>412.50000</td>\n",
       "      <td>1929.500000</td>\n",
       "      <td>151558.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.510207</td>\n",
       "      <td>0.286958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.267500</td>\n",
       "      <td>0.55570</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.189997</td>\n",
       "      <td>0.224587</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.036125</td>\n",
       "      <td>0.10005</td>\n",
       "      <td>0.257700</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.161635</td>\n",
       "      <td>0.221854</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.027600</td>\n",
       "      <td>0.07140</td>\n",
       "      <td>0.198875</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.033544</td>\n",
       "      <td>0.073777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.01290</td>\n",
       "      <td>0.032700</td>\n",
       "      <td>0.9727</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.013813</td>\n",
       "      <td>0.070196</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00260</td>\n",
       "      <td>0.007300</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.004569</td>\n",
       "      <td>0.033125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.9983</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.023950</td>\n",
       "      <td>0.031288</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01750</td>\n",
       "      <td>0.033900</td>\n",
       "      <td>0.5333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.016086</td>\n",
       "      <td>0.050172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.011700</td>\n",
       "      <td>0.9286</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.045181</td>\n",
       "      <td>0.093440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01430</td>\n",
       "      <td>0.045400</td>\n",
       "      <td>0.9027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <td>6853.0</td>\n",
       "      <td>0.226639</td>\n",
       "      <td>0.246470</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.15040</td>\n",
       "      <td>0.376900</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.923291</td>\n",
       "      <td>0.266146</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.357800</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.332900</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.241500</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               count         mean          std    min         25%        50%  \\\n",
       "HBCU          7164.0     0.014238     0.118478    0.0    0.000000    0.00000   \n",
       "MENONLY       7164.0     0.009213     0.095546    0.0    0.000000    0.00000   \n",
       "WOMENONLY     7164.0     0.005304     0.072642    0.0    0.000000    0.00000   \n",
       "RELAFFIL      7535.0     0.190975     0.393096    0.0    0.000000    0.00000   \n",
       "SATVRMID      1185.0   522.819409    68.578862  290.0  475.000000  510.00000   \n",
       "SATMTMID      1196.0   530.765050    73.469767  310.0  482.000000  520.00000   \n",
       "DISTANCEONLY  7164.0     0.005583     0.074519    0.0    0.000000    0.00000   \n",
       "UGDS          6874.0  2356.837940  5474.275871    0.0  117.000000  412.50000   \n",
       "UGDS_WHITE    6874.0     0.510207     0.286958    0.0    0.267500    0.55570   \n",
       "UGDS_BLACK    6874.0     0.189997     0.224587    0.0    0.036125    0.10005   \n",
       "UGDS_HISP     6874.0     0.161635     0.221854    0.0    0.027600    0.07140   \n",
       "UGDS_ASIAN    6874.0     0.033544     0.073777    0.0    0.002500    0.01290   \n",
       "UGDS_AIAN     6874.0     0.013813     0.070196    0.0    0.000000    0.00260   \n",
       "UGDS_NHPI     6874.0     0.004569     0.033125    0.0    0.000000    0.00000   \n",
       "UGDS_2MOR     6874.0     0.023950     0.031288    0.0    0.000000    0.01750   \n",
       "UGDS_NRA      6874.0     0.016086     0.050172    0.0    0.000000    0.00000   \n",
       "UGDS_UNKN     6874.0     0.045181     0.093440    0.0    0.000000    0.01430   \n",
       "PPTUG_EF      6853.0     0.226639     0.246470    0.0    0.000000    0.15040   \n",
       "CURROPER      7535.0     0.923291     0.266146    0.0    1.000000    1.00000   \n",
       "PCTPELL       6849.0     0.530643     0.225544    0.0    0.357800    0.52150   \n",
       "PCTFLOAN      6849.0     0.522211     0.283616    0.0    0.332900    0.58330   \n",
       "UG25ABV       6718.0     0.410021     0.228939    0.0    0.241500    0.40075   \n",
       "\n",
       "                      75%          max  \n",
       "HBCU             0.000000       1.0000  \n",
       "MENONLY          0.000000       1.0000  \n",
       "WOMENONLY        0.000000       1.0000  \n",
       "RELAFFIL         0.000000       1.0000  \n",
       "SATVRMID       555.000000     765.0000  \n",
       "SATMTMID       565.000000     785.0000  \n",
       "DISTANCEONLY     0.000000       1.0000  \n",
       "UGDS          1929.500000  151558.0000  \n",
       "UGDS_WHITE       0.747875       1.0000  \n",
       "UGDS_BLACK       0.257700       1.0000  \n",
       "UGDS_HISP        0.198875       1.0000  \n",
       "UGDS_ASIAN       0.032700       0.9727  \n",
       "UGDS_AIAN        0.007300       1.0000  \n",
       "UGDS_NHPI        0.002500       0.9983  \n",
       "UGDS_2MOR        0.033900       0.5333  \n",
       "UGDS_NRA         0.011700       0.9286  \n",
       "UGDS_UNKN        0.045400       0.9027  \n",
       "PPTUG_EF         0.376900       1.0000  \n",
       "CURROPER         1.000000       1.0000  \n",
       "PCTPELL          0.712900       1.0000  \n",
       "PCTFLOAN         0.745000       1.0000  \n",
       "UG25ABV          0.572275       1.0000  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=[np.number]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>unique</th>\n",
       "      <th>top</th>\n",
       "      <th>freq</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <td>7535</td>\n",
       "      <td>7535</td>\n",
       "      <td>San Francisco State University</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CITY</th>\n",
       "      <td>7535</td>\n",
       "      <td>2514</td>\n",
       "      <td>New York</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>STABBR</th>\n",
       "      <td>7535</td>\n",
       "      <td>59</td>\n",
       "      <td>CA</td>\n",
       "      <td>773</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <td>6413</td>\n",
       "      <td>598</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>822</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "      <td>7503</td>\n",
       "      <td>2038</td>\n",
       "      <td>PrivacySuppressed</td>\n",
       "      <td>1510</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   count unique                             top  freq\n",
       "INSTNM              7535   7535  San Francisco State University     1\n",
       "CITY                7535   2514                        New York    87\n",
       "STABBR              7535     59                              CA   773\n",
       "MD_EARN_WNE_P10     6413    598               PrivacySuppressed   822\n",
       "GRAD_DEBT_MDN_SUPP  7503   2038               PrivacySuppressed  1510"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=[np.object, pd.Categorical]).T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>1%</th>\n",
       "      <th>5%</th>\n",
       "      <th>10%</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>90%</th>\n",
       "      <th>95%</th>\n",
       "      <th>99%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.3329</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>0.84752</td>\n",
       "      <td>0.89792</td>\n",
       "      <td>0.986368</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0025</td>\n",
       "      <td>0.0374</td>\n",
       "      <td>0.0899</td>\n",
       "      <td>0.2415</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>0.72666</td>\n",
       "      <td>0.80000</td>\n",
       "      <td>0.917383</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>22 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           count      mean       std  min      1%      5%     10%     25%  \\\n",
       "HBCU      7164.0  0.014238  0.118478  0.0  0.0000  0.0000  0.0000  0.0000   \n",
       "MENONLY   7164.0  0.009213  0.095546  0.0  0.0000  0.0000  0.0000  0.0000   \n",
       "...          ...       ...       ...  ...     ...     ...     ...     ...   \n",
       "PCTFLOAN  6849.0  0.522211  0.283616  0.0  0.0000  0.0000  0.0000  0.3329   \n",
       "UG25ABV   6718.0  0.410021  0.228939  0.0  0.0025  0.0374  0.0899  0.2415   \n",
       "\n",
       "              50%       75%      90%      95%       99%  max  \n",
       "HBCU      0.00000  0.000000  0.00000  0.00000  1.000000  1.0  \n",
       "MENONLY   0.00000  0.000000  0.00000  0.00000  0.000000  1.0  \n",
       "...           ...       ...      ...      ...       ...  ...  \n",
       "PCTFLOAN  0.58330  0.745000  0.84752  0.89792  0.986368  1.0  \n",
       "UG25ABV   0.40075  0.572275  0.72666  0.80000  0.917383  1.0  \n",
       "\n",
       "[22 rows x 14 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with pd.option_context('display.max_rows', 5):\n",
    "    display(college.describe(include=[np.number], \n",
    "                 percentiles=[.01, .05, .10, .25, .5, .75, .9, .95, .99]).T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "college_dd = pd.read_csv('data/college_data_dictionary.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>column_name</th>\n",
       "      <th>description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>INSTNM</td>\n",
       "      <td>Institution Name</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>CITY</td>\n",
       "      <td>City Location</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>STABBR</td>\n",
       "      <td>State Abbreviation</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HBCU</td>\n",
       "      <td>Historically Black College or University</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>PCTFLOAN</td>\n",
       "      <td>Percent Students with federal loan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>UG25ABV</td>\n",
       "      <td>Percent Students Older than 25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>MD_EARN_WNE_P10</td>\n",
       "      <td>Median Earnings 10 years after enrollment</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>GRAD_DEBT_MDN_SUPP</td>\n",
       "      <td>Median debt of completers</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>27 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           column_name                                description\n",
       "0               INSTNM                           Institution Name\n",
       "1                 CITY                              City Location\n",
       "2               STABBR                         State Abbreviation\n",
       "3                 HBCU   Historically Black College or University\n",
       "..                 ...                                        ...\n",
       "23            PCTFLOAN         Percent Students with federal loan\n",
       "24             UG25ABV             Percent Students Older than 25\n",
       "25     MD_EARN_WNE_P10  Median Earnings 10 years after enrollment\n",
       "26  GRAD_DEBT_MDN_SUPP                  Median debt of completers\n",
       "\n",
       "[27 rows x 2 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "with pd.option_context('display.max_rows', 8):\n",
    "    display(college_dd)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Reducing memory by changing data types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>INSTNM</th>\n",
       "      <th>STABBR</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>420.0</td>\n",
       "      <td>1</td>\n",
       "      <td>Alabama A &amp; M University</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>565.0</td>\n",
       "      <td>1</td>\n",
       "      <td>University of Alabama at Birmingham</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>Amridge University</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>1</td>\n",
       "      <td>University of Alabama in Huntsville</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>430.0</td>\n",
       "      <td>1</td>\n",
       "      <td>Alabama State University</td>\n",
       "      <td>AL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   RELAFFIL  SATMTMID  CURROPER                               INSTNM STABBR\n",
       "0         0     420.0         1             Alabama A & M University     AL\n",
       "1         0     565.0         1  University of Alabama at Birmingham     AL\n",
       "2         1       NaN         1                   Amridge University     AL\n",
       "3         0     590.0         1  University of Alabama in Huntsville     AL\n",
       "4         0     430.0         1             Alabama State University     AL"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv')\n",
    "different_cols = ['RELAFFIL', 'SATMTMID', 'CURROPER', 'INSTNM', 'STABBR']\n",
    "col2 = college.loc[:, different_cols]\n",
    "col2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RELAFFIL      int64\n",
       "SATMTMID    float64\n",
       "CURROPER      int64\n",
       "INSTNM       object\n",
       "STABBR       object\n",
       "dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index           80\n",
       "RELAFFIL     60280\n",
       "SATMTMID     60280\n",
       "CURROPER     60280\n",
       "INSTNM      660240\n",
       "STABBR      444565\n",
       "dtype: int64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "original_mem = col2.memory_usage(deep=True)\n",
    "original_mem"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "col2['RELAFFIL'] = col2['RELAFFIL'].astype(np.int8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RELAFFIL       int8\n",
       "SATMTMID    float64\n",
       "CURROPER      int64\n",
       "INSTNM       object\n",
       "STABBR       object\n",
       "dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM    7535\n",
       "STABBR      59\n",
       "dtype: int64"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col2.select_dtypes(include=['object']).nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RELAFFIL        int8\n",
       "SATMTMID     float64\n",
       "CURROPER       int64\n",
       "INSTNM        object\n",
       "STABBR      category\n",
       "dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "col2['STABBR'] = col2['STABBR'].astype('category')\n",
    "col2.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index           80\n",
       "RELAFFIL      7535\n",
       "SATMTMID     60280\n",
       "CURROPER     60280\n",
       "INSTNM      660699\n",
       "STABBR       13576\n",
       "dtype: int64"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_mem = col2.memory_usage(deep=True)\n",
    "new_mem"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index       1.000000\n",
       "RELAFFIL    0.125000\n",
       "SATMTMID    1.000000\n",
       "CURROPER    1.000000\n",
       "INSTNM      1.000695\n",
       "STABBR      0.030538\n",
       "dtype: float64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_mem / original_mem"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "college = pd.read_csv('data/college.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index           80\n",
       "CURROPER     60280\n",
       "INSTNM      660240\n",
       "dtype: int64"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college[['CURROPER', 'INSTNM']].memory_usage(deep=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index           80\n",
       "CURROPER     60280\n",
       "INSTNM      660345\n",
       "dtype: int64"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.loc[0, 'CURROPER'] = 10000000\n",
    "college.loc[0, 'INSTNM'] = college.loc[0, 'INSTNM'] + 'a'\n",
    "# college.loc[1, 'INSTNM'] = college.loc[1, 'INSTNM'] + 'a'\n",
    "college[['CURROPER', 'INSTNM']].memory_usage(deep=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('float64')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college['MENONLY'].dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "Cannot convert non-finite values (NA or inf) to integer",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-26-98afc27c1701>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcollege\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'MENONLY'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'int8'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# ValueError: Cannot convert non-finite values (NA or inf) to integer\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/util/_decorators.py\u001b[0m in \u001b[0;36mwrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    116\u001b[0m                 \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    117\u001b[0m                     \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnew_arg_name\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnew_arg_value\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 118\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    119\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    120\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0m_deprecate_kwarg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mastype\u001b[0;34m(self, dtype, copy, errors, **kwargs)\u001b[0m\n\u001b[1;32m   4002\u001b[0m         \u001b[0;31m# else, only a single dtype is given\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4003\u001b[0m         new_data = self._data.astype(dtype=dtype, copy=copy, errors=errors,\n\u001b[0;32m-> 4004\u001b[0;31m                                      **kwargs)\n\u001b[0m\u001b[1;32m   4005\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_constructor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnew_data\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__finalize__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   4006\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mastype\u001b[0;34m(self, dtype, **kwargs)\u001b[0m\n\u001b[1;32m   3455\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3456\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3457\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'astype'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3458\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3459\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mapply\u001b[0;34m(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)\u001b[0m\n\u001b[1;32m   3322\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3323\u001b[0m             \u001b[0mkwargs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'mgr'\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3324\u001b[0;31m             \u001b[0mapplied\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   3325\u001b[0m             \u001b[0mresult_blocks\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_extend_blocks\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mapplied\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult_blocks\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   3326\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36mastype\u001b[0;34m(self, dtype, copy, errors, values, **kwargs)\u001b[0m\n\u001b[1;32m    542\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'raise'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    543\u001b[0m         return self._astype(dtype, copy=copy, errors=errors, values=values,\n\u001b[0;32m--> 544\u001b[0;31m                             **kwargs)\n\u001b[0m\u001b[1;32m    545\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    546\u001b[0m     def _astype(self, dtype, copy=False, errors='raise', values=None,\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/internals.py\u001b[0m in \u001b[0;36m_astype\u001b[0;34m(self, dtype, copy, errors, values, klass, mgr, **kwargs)\u001b[0m\n\u001b[1;32m    623\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    624\u001b[0m                 \u001b[0;31m# _astype_nansafe works fine with 1-d only\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 625\u001b[0;31m                 \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mastype_nansafe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mravel\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    626\u001b[0m                 \u001b[0mvalues\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mvalues\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreshape\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    627\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/lib/python3.6/site-packages/pandas/core/dtypes/cast.py\u001b[0m in \u001b[0;36mastype_nansafe\u001b[0;34m(arr, dtype, copy)\u001b[0m\n\u001b[1;32m    685\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    686\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misfinite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 687\u001b[0;31m             raise ValueError('Cannot convert non-finite values (NA or inf) to '\n\u001b[0m\u001b[1;32m    688\u001b[0m                              'integer')\n\u001b[1;32m    689\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mValueError\u001b[0m: Cannot convert non-finite values (NA or inf) to integer"
     ]
    }
   ],
   "source": [
    "college['MENONLY'].astype('int8') # ValueError: Cannot convert non-finite values (NA or inf) to integer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RELAFFIL</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.190975</td>\n",
       "      <td>0.393096</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATVRMID</th>\n",
       "      <td>1185.0</td>\n",
       "      <td>522.819409</td>\n",
       "      <td>68.578862</td>\n",
       "      <td>290.0</td>\n",
       "      <td>475.000000</td>\n",
       "      <td>510.00000</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>7.650000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATMTMID</th>\n",
       "      <td>1196.0</td>\n",
       "      <td>530.765050</td>\n",
       "      <td>73.469767</td>\n",
       "      <td>310.0</td>\n",
       "      <td>482.000000</td>\n",
       "      <td>520.00000</td>\n",
       "      <td>565.000000</td>\n",
       "      <td>7.850000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005583</td>\n",
       "      <td>0.074519</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>2356.837940</td>\n",
       "      <td>5474.275871</td>\n",
       "      <td>0.0</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>412.50000</td>\n",
       "      <td>1929.500000</td>\n",
       "      <td>1.515580e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.510207</td>\n",
       "      <td>0.286958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.267500</td>\n",
       "      <td>0.55570</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.189997</td>\n",
       "      <td>0.224587</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.036125</td>\n",
       "      <td>0.10005</td>\n",
       "      <td>0.257700</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.161635</td>\n",
       "      <td>0.221854</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.027600</td>\n",
       "      <td>0.07140</td>\n",
       "      <td>0.198875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.033544</td>\n",
       "      <td>0.073777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.01290</td>\n",
       "      <td>0.032700</td>\n",
       "      <td>9.727000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.013813</td>\n",
       "      <td>0.070196</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00260</td>\n",
       "      <td>0.007300</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.004569</td>\n",
       "      <td>0.033125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>9.983000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.023950</td>\n",
       "      <td>0.031288</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01750</td>\n",
       "      <td>0.033900</td>\n",
       "      <td>5.333000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.016086</td>\n",
       "      <td>0.050172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.011700</td>\n",
       "      <td>9.286000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.045181</td>\n",
       "      <td>0.093440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01430</td>\n",
       "      <td>0.045400</td>\n",
       "      <td>9.027000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <td>6853.0</td>\n",
       "      <td>0.226639</td>\n",
       "      <td>0.246470</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.15040</td>\n",
       "      <td>0.376900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>1328.063172</td>\n",
       "      <td>115201.552429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.357800</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.332900</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.241500</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               count         mean            std    min         25%  \\\n",
       "HBCU          7164.0     0.014238       0.118478    0.0    0.000000   \n",
       "MENONLY       7164.0     0.009213       0.095546    0.0    0.000000   \n",
       "WOMENONLY     7164.0     0.005304       0.072642    0.0    0.000000   \n",
       "RELAFFIL      7535.0     0.190975       0.393096    0.0    0.000000   \n",
       "SATVRMID      1185.0   522.819409      68.578862  290.0  475.000000   \n",
       "SATMTMID      1196.0   530.765050      73.469767  310.0  482.000000   \n",
       "DISTANCEONLY  7164.0     0.005583       0.074519    0.0    0.000000   \n",
       "UGDS          6874.0  2356.837940    5474.275871    0.0  117.000000   \n",
       "UGDS_WHITE    6874.0     0.510207       0.286958    0.0    0.267500   \n",
       "UGDS_BLACK    6874.0     0.189997       0.224587    0.0    0.036125   \n",
       "UGDS_HISP     6874.0     0.161635       0.221854    0.0    0.027600   \n",
       "UGDS_ASIAN    6874.0     0.033544       0.073777    0.0    0.002500   \n",
       "UGDS_AIAN     6874.0     0.013813       0.070196    0.0    0.000000   \n",
       "UGDS_NHPI     6874.0     0.004569       0.033125    0.0    0.000000   \n",
       "UGDS_2MOR     6874.0     0.023950       0.031288    0.0    0.000000   \n",
       "UGDS_NRA      6874.0     0.016086       0.050172    0.0    0.000000   \n",
       "UGDS_UNKN     6874.0     0.045181       0.093440    0.0    0.000000   \n",
       "PPTUG_EF      6853.0     0.226639       0.246470    0.0    0.000000   \n",
       "CURROPER      7535.0  1328.063172  115201.552429    0.0    1.000000   \n",
       "PCTPELL       6849.0     0.530643       0.225544    0.0    0.357800   \n",
       "PCTFLOAN      6849.0     0.522211       0.283616    0.0    0.332900   \n",
       "UG25ABV       6718.0     0.410021       0.228939    0.0    0.241500   \n",
       "\n",
       "                    50%          75%           max  \n",
       "HBCU            0.00000     0.000000  1.000000e+00  \n",
       "MENONLY         0.00000     0.000000  1.000000e+00  \n",
       "WOMENONLY       0.00000     0.000000  1.000000e+00  \n",
       "RELAFFIL        0.00000     0.000000  1.000000e+00  \n",
       "SATVRMID      510.00000   555.000000  7.650000e+02  \n",
       "SATMTMID      520.00000   565.000000  7.850000e+02  \n",
       "DISTANCEONLY    0.00000     0.000000  1.000000e+00  \n",
       "UGDS          412.50000  1929.500000  1.515580e+05  \n",
       "UGDS_WHITE      0.55570     0.747875  1.000000e+00  \n",
       "UGDS_BLACK      0.10005     0.257700  1.000000e+00  \n",
       "UGDS_HISP       0.07140     0.198875  1.000000e+00  \n",
       "UGDS_ASIAN      0.01290     0.032700  9.727000e-01  \n",
       "UGDS_AIAN       0.00260     0.007300  1.000000e+00  \n",
       "UGDS_NHPI       0.00000     0.002500  9.983000e-01  \n",
       "UGDS_2MOR       0.01750     0.033900  5.333000e-01  \n",
       "UGDS_NRA        0.00000     0.011700  9.286000e-01  \n",
       "UGDS_UNKN       0.01430     0.045400  9.027000e-01  \n",
       "PPTUG_EF        0.15040     0.376900  1.000000e+00  \n",
       "CURROPER        1.00000     1.000000  1.000000e+07  \n",
       "PCTPELL         0.52150     0.712900  1.000000e+00  \n",
       "PCTFLOAN        0.58330     0.745000  1.000000e+00  \n",
       "UG25ABV         0.40075     0.572275  1.000000e+00  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=['int64', 'float64']).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RELAFFIL</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.190975</td>\n",
       "      <td>0.393096</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATVRMID</th>\n",
       "      <td>1185.0</td>\n",
       "      <td>522.819409</td>\n",
       "      <td>68.578862</td>\n",
       "      <td>290.0</td>\n",
       "      <td>475.000000</td>\n",
       "      <td>510.00000</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>7.650000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATMTMID</th>\n",
       "      <td>1196.0</td>\n",
       "      <td>530.765050</td>\n",
       "      <td>73.469767</td>\n",
       "      <td>310.0</td>\n",
       "      <td>482.000000</td>\n",
       "      <td>520.00000</td>\n",
       "      <td>565.000000</td>\n",
       "      <td>7.850000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005583</td>\n",
       "      <td>0.074519</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>2356.837940</td>\n",
       "      <td>5474.275871</td>\n",
       "      <td>0.0</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>412.50000</td>\n",
       "      <td>1929.500000</td>\n",
       "      <td>1.515580e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.510207</td>\n",
       "      <td>0.286958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.267500</td>\n",
       "      <td>0.55570</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.189997</td>\n",
       "      <td>0.224587</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.036125</td>\n",
       "      <td>0.10005</td>\n",
       "      <td>0.257700</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.161635</td>\n",
       "      <td>0.221854</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.027600</td>\n",
       "      <td>0.07140</td>\n",
       "      <td>0.198875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.033544</td>\n",
       "      <td>0.073777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.01290</td>\n",
       "      <td>0.032700</td>\n",
       "      <td>9.727000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.013813</td>\n",
       "      <td>0.070196</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00260</td>\n",
       "      <td>0.007300</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.004569</td>\n",
       "      <td>0.033125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>9.983000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.023950</td>\n",
       "      <td>0.031288</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01750</td>\n",
       "      <td>0.033900</td>\n",
       "      <td>5.333000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.016086</td>\n",
       "      <td>0.050172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.011700</td>\n",
       "      <td>9.286000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.045181</td>\n",
       "      <td>0.093440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01430</td>\n",
       "      <td>0.045400</td>\n",
       "      <td>9.027000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <td>6853.0</td>\n",
       "      <td>0.226639</td>\n",
       "      <td>0.246470</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.15040</td>\n",
       "      <td>0.376900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>1328.063172</td>\n",
       "      <td>115201.552429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.357800</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.332900</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.241500</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               count         mean            std    min         25%  \\\n",
       "HBCU          7164.0     0.014238       0.118478    0.0    0.000000   \n",
       "MENONLY       7164.0     0.009213       0.095546    0.0    0.000000   \n",
       "WOMENONLY     7164.0     0.005304       0.072642    0.0    0.000000   \n",
       "RELAFFIL      7535.0     0.190975       0.393096    0.0    0.000000   \n",
       "SATVRMID      1185.0   522.819409      68.578862  290.0  475.000000   \n",
       "SATMTMID      1196.0   530.765050      73.469767  310.0  482.000000   \n",
       "DISTANCEONLY  7164.0     0.005583       0.074519    0.0    0.000000   \n",
       "UGDS          6874.0  2356.837940    5474.275871    0.0  117.000000   \n",
       "UGDS_WHITE    6874.0     0.510207       0.286958    0.0    0.267500   \n",
       "UGDS_BLACK    6874.0     0.189997       0.224587    0.0    0.036125   \n",
       "UGDS_HISP     6874.0     0.161635       0.221854    0.0    0.027600   \n",
       "UGDS_ASIAN    6874.0     0.033544       0.073777    0.0    0.002500   \n",
       "UGDS_AIAN     6874.0     0.013813       0.070196    0.0    0.000000   \n",
       "UGDS_NHPI     6874.0     0.004569       0.033125    0.0    0.000000   \n",
       "UGDS_2MOR     6874.0     0.023950       0.031288    0.0    0.000000   \n",
       "UGDS_NRA      6874.0     0.016086       0.050172    0.0    0.000000   \n",
       "UGDS_UNKN     6874.0     0.045181       0.093440    0.0    0.000000   \n",
       "PPTUG_EF      6853.0     0.226639       0.246470    0.0    0.000000   \n",
       "CURROPER      7535.0  1328.063172  115201.552429    0.0    1.000000   \n",
       "PCTPELL       6849.0     0.530643       0.225544    0.0    0.357800   \n",
       "PCTFLOAN      6849.0     0.522211       0.283616    0.0    0.332900   \n",
       "UG25ABV       6718.0     0.410021       0.228939    0.0    0.241500   \n",
       "\n",
       "                    50%          75%           max  \n",
       "HBCU            0.00000     0.000000  1.000000e+00  \n",
       "MENONLY         0.00000     0.000000  1.000000e+00  \n",
       "WOMENONLY       0.00000     0.000000  1.000000e+00  \n",
       "RELAFFIL        0.00000     0.000000  1.000000e+00  \n",
       "SATVRMID      510.00000   555.000000  7.650000e+02  \n",
       "SATMTMID      520.00000   565.000000  7.850000e+02  \n",
       "DISTANCEONLY    0.00000     0.000000  1.000000e+00  \n",
       "UGDS          412.50000  1929.500000  1.515580e+05  \n",
       "UGDS_WHITE      0.55570     0.747875  1.000000e+00  \n",
       "UGDS_BLACK      0.10005     0.257700  1.000000e+00  \n",
       "UGDS_HISP       0.07140     0.198875  1.000000e+00  \n",
       "UGDS_ASIAN      0.01290     0.032700  9.727000e-01  \n",
       "UGDS_AIAN       0.00260     0.007300  1.000000e+00  \n",
       "UGDS_NHPI       0.00000     0.002500  9.983000e-01  \n",
       "UGDS_2MOR       0.01750     0.033900  5.333000e-01  \n",
       "UGDS_NRA        0.00000     0.011700  9.286000e-01  \n",
       "UGDS_UNKN       0.01430     0.045400  9.027000e-01  \n",
       "PPTUG_EF        0.15040     0.376900  1.000000e+00  \n",
       "CURROPER        1.00000     1.000000  1.000000e+07  \n",
       "PCTPELL         0.52150     0.712900  1.000000e+00  \n",
       "PCTFLOAN        0.58330     0.745000  1.000000e+00  \n",
       "UG25ABV         0.40075     0.572275  1.000000e+00  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=[np.int64, np.float64]).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "college['RELAFFIL'] = college['RELAFFIL'].astype(np.int8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATVRMID</th>\n",
       "      <td>1185.0</td>\n",
       "      <td>522.819409</td>\n",
       "      <td>68.578862</td>\n",
       "      <td>290.0</td>\n",
       "      <td>475.000000</td>\n",
       "      <td>510.00000</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>7.650000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATMTMID</th>\n",
       "      <td>1196.0</td>\n",
       "      <td>530.765050</td>\n",
       "      <td>73.469767</td>\n",
       "      <td>310.0</td>\n",
       "      <td>482.000000</td>\n",
       "      <td>520.00000</td>\n",
       "      <td>565.000000</td>\n",
       "      <td>7.850000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005583</td>\n",
       "      <td>0.074519</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>2356.837940</td>\n",
       "      <td>5474.275871</td>\n",
       "      <td>0.0</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>412.50000</td>\n",
       "      <td>1929.500000</td>\n",
       "      <td>1.515580e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.510207</td>\n",
       "      <td>0.286958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.267500</td>\n",
       "      <td>0.55570</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.189997</td>\n",
       "      <td>0.224587</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.036125</td>\n",
       "      <td>0.10005</td>\n",
       "      <td>0.257700</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.161635</td>\n",
       "      <td>0.221854</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.027600</td>\n",
       "      <td>0.07140</td>\n",
       "      <td>0.198875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.033544</td>\n",
       "      <td>0.073777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.01290</td>\n",
       "      <td>0.032700</td>\n",
       "      <td>9.727000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.013813</td>\n",
       "      <td>0.070196</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00260</td>\n",
       "      <td>0.007300</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.004569</td>\n",
       "      <td>0.033125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>9.983000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.023950</td>\n",
       "      <td>0.031288</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01750</td>\n",
       "      <td>0.033900</td>\n",
       "      <td>5.333000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.016086</td>\n",
       "      <td>0.050172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.011700</td>\n",
       "      <td>9.286000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.045181</td>\n",
       "      <td>0.093440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01430</td>\n",
       "      <td>0.045400</td>\n",
       "      <td>9.027000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <td>6853.0</td>\n",
       "      <td>0.226639</td>\n",
       "      <td>0.246470</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.15040</td>\n",
       "      <td>0.376900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>1328.063172</td>\n",
       "      <td>115201.552429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.357800</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.332900</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.241500</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               count         mean            std    min         25%  \\\n",
       "HBCU          7164.0     0.014238       0.118478    0.0    0.000000   \n",
       "MENONLY       7164.0     0.009213       0.095546    0.0    0.000000   \n",
       "WOMENONLY     7164.0     0.005304       0.072642    0.0    0.000000   \n",
       "SATVRMID      1185.0   522.819409      68.578862  290.0  475.000000   \n",
       "SATMTMID      1196.0   530.765050      73.469767  310.0  482.000000   \n",
       "DISTANCEONLY  7164.0     0.005583       0.074519    0.0    0.000000   \n",
       "UGDS          6874.0  2356.837940    5474.275871    0.0  117.000000   \n",
       "UGDS_WHITE    6874.0     0.510207       0.286958    0.0    0.267500   \n",
       "UGDS_BLACK    6874.0     0.189997       0.224587    0.0    0.036125   \n",
       "UGDS_HISP     6874.0     0.161635       0.221854    0.0    0.027600   \n",
       "UGDS_ASIAN    6874.0     0.033544       0.073777    0.0    0.002500   \n",
       "UGDS_AIAN     6874.0     0.013813       0.070196    0.0    0.000000   \n",
       "UGDS_NHPI     6874.0     0.004569       0.033125    0.0    0.000000   \n",
       "UGDS_2MOR     6874.0     0.023950       0.031288    0.0    0.000000   \n",
       "UGDS_NRA      6874.0     0.016086       0.050172    0.0    0.000000   \n",
       "UGDS_UNKN     6874.0     0.045181       0.093440    0.0    0.000000   \n",
       "PPTUG_EF      6853.0     0.226639       0.246470    0.0    0.000000   \n",
       "CURROPER      7535.0  1328.063172  115201.552429    0.0    1.000000   \n",
       "PCTPELL       6849.0     0.530643       0.225544    0.0    0.357800   \n",
       "PCTFLOAN      6849.0     0.522211       0.283616    0.0    0.332900   \n",
       "UG25ABV       6718.0     0.410021       0.228939    0.0    0.241500   \n",
       "\n",
       "                    50%          75%           max  \n",
       "HBCU            0.00000     0.000000  1.000000e+00  \n",
       "MENONLY         0.00000     0.000000  1.000000e+00  \n",
       "WOMENONLY       0.00000     0.000000  1.000000e+00  \n",
       "SATVRMID      510.00000   555.000000  7.650000e+02  \n",
       "SATMTMID      520.00000   565.000000  7.850000e+02  \n",
       "DISTANCEONLY    0.00000     0.000000  1.000000e+00  \n",
       "UGDS          412.50000  1929.500000  1.515580e+05  \n",
       "UGDS_WHITE      0.55570     0.747875  1.000000e+00  \n",
       "UGDS_BLACK      0.10005     0.257700  1.000000e+00  \n",
       "UGDS_HISP       0.07140     0.198875  1.000000e+00  \n",
       "UGDS_ASIAN      0.01290     0.032700  9.727000e-01  \n",
       "UGDS_AIAN       0.00260     0.007300  1.000000e+00  \n",
       "UGDS_NHPI       0.00000     0.002500  9.983000e-01  \n",
       "UGDS_2MOR       0.01750     0.033900  5.333000e-01  \n",
       "UGDS_NRA        0.00000     0.011700  9.286000e-01  \n",
       "UGDS_UNKN       0.01430     0.045400  9.027000e-01  \n",
       "PPTUG_EF        0.15040     0.376900  1.000000e+00  \n",
       "CURROPER        1.00000     1.000000  1.000000e+07  \n",
       "PCTPELL         0.52150     0.712900  1.000000e+00  \n",
       "PCTFLOAN        0.58330     0.745000  1.000000e+00  \n",
       "UG25ABV         0.40075     0.572275  1.000000e+00  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=['int', 'float']).T  # defaults to 64 bit int/floats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>HBCU</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.014238</td>\n",
       "      <td>0.118478</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.009213</td>\n",
       "      <td>0.095546</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WOMENONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005304</td>\n",
       "      <td>0.072642</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RELAFFIL</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>0.190975</td>\n",
       "      <td>0.393096</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATVRMID</th>\n",
       "      <td>1185.0</td>\n",
       "      <td>522.819409</td>\n",
       "      <td>68.578862</td>\n",
       "      <td>290.0</td>\n",
       "      <td>475.000000</td>\n",
       "      <td>510.00000</td>\n",
       "      <td>555.000000</td>\n",
       "      <td>7.650000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SATMTMID</th>\n",
       "      <td>1196.0</td>\n",
       "      <td>530.765050</td>\n",
       "      <td>73.469767</td>\n",
       "      <td>310.0</td>\n",
       "      <td>482.000000</td>\n",
       "      <td>520.00000</td>\n",
       "      <td>565.000000</td>\n",
       "      <td>7.850000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <td>7164.0</td>\n",
       "      <td>0.005583</td>\n",
       "      <td>0.074519</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>2356.837940</td>\n",
       "      <td>5474.275871</td>\n",
       "      <td>0.0</td>\n",
       "      <td>117.000000</td>\n",
       "      <td>412.50000</td>\n",
       "      <td>1929.500000</td>\n",
       "      <td>1.515580e+05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.510207</td>\n",
       "      <td>0.286958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.267500</td>\n",
       "      <td>0.55570</td>\n",
       "      <td>0.747875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.189997</td>\n",
       "      <td>0.224587</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.036125</td>\n",
       "      <td>0.10005</td>\n",
       "      <td>0.257700</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.161635</td>\n",
       "      <td>0.221854</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.027600</td>\n",
       "      <td>0.07140</td>\n",
       "      <td>0.198875</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.033544</td>\n",
       "      <td>0.073777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>0.01290</td>\n",
       "      <td>0.032700</td>\n",
       "      <td>9.727000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.013813</td>\n",
       "      <td>0.070196</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00260</td>\n",
       "      <td>0.007300</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.004569</td>\n",
       "      <td>0.033125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.002500</td>\n",
       "      <td>9.983000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.023950</td>\n",
       "      <td>0.031288</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01750</td>\n",
       "      <td>0.033900</td>\n",
       "      <td>5.333000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.016086</td>\n",
       "      <td>0.050172</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.011700</td>\n",
       "      <td>9.286000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <td>6874.0</td>\n",
       "      <td>0.045181</td>\n",
       "      <td>0.093440</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.01430</td>\n",
       "      <td>0.045400</td>\n",
       "      <td>9.027000e-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <td>6853.0</td>\n",
       "      <td>0.226639</td>\n",
       "      <td>0.246470</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.15040</td>\n",
       "      <td>0.376900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CURROPER</th>\n",
       "      <td>7535.0</td>\n",
       "      <td>1328.063172</td>\n",
       "      <td>115201.552429</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.00000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTPELL</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.530643</td>\n",
       "      <td>0.225544</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.357800</td>\n",
       "      <td>0.52150</td>\n",
       "      <td>0.712900</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <td>6849.0</td>\n",
       "      <td>0.522211</td>\n",
       "      <td>0.283616</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.332900</td>\n",
       "      <td>0.58330</td>\n",
       "      <td>0.745000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>UG25ABV</th>\n",
       "      <td>6718.0</td>\n",
       "      <td>0.410021</td>\n",
       "      <td>0.228939</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.241500</td>\n",
       "      <td>0.40075</td>\n",
       "      <td>0.572275</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               count         mean            std    min         25%  \\\n",
       "HBCU          7164.0     0.014238       0.118478    0.0    0.000000   \n",
       "MENONLY       7164.0     0.009213       0.095546    0.0    0.000000   \n",
       "WOMENONLY     7164.0     0.005304       0.072642    0.0    0.000000   \n",
       "RELAFFIL      7535.0     0.190975       0.393096    0.0    0.000000   \n",
       "SATVRMID      1185.0   522.819409      68.578862  290.0  475.000000   \n",
       "SATMTMID      1196.0   530.765050      73.469767  310.0  482.000000   \n",
       "DISTANCEONLY  7164.0     0.005583       0.074519    0.0    0.000000   \n",
       "UGDS          6874.0  2356.837940    5474.275871    0.0  117.000000   \n",
       "UGDS_WHITE    6874.0     0.510207       0.286958    0.0    0.267500   \n",
       "UGDS_BLACK    6874.0     0.189997       0.224587    0.0    0.036125   \n",
       "UGDS_HISP     6874.0     0.161635       0.221854    0.0    0.027600   \n",
       "UGDS_ASIAN    6874.0     0.033544       0.073777    0.0    0.002500   \n",
       "UGDS_AIAN     6874.0     0.013813       0.070196    0.0    0.000000   \n",
       "UGDS_NHPI     6874.0     0.004569       0.033125    0.0    0.000000   \n",
       "UGDS_2MOR     6874.0     0.023950       0.031288    0.0    0.000000   \n",
       "UGDS_NRA      6874.0     0.016086       0.050172    0.0    0.000000   \n",
       "UGDS_UNKN     6874.0     0.045181       0.093440    0.0    0.000000   \n",
       "PPTUG_EF      6853.0     0.226639       0.246470    0.0    0.000000   \n",
       "CURROPER      7535.0  1328.063172  115201.552429    0.0    1.000000   \n",
       "PCTPELL       6849.0     0.530643       0.225544    0.0    0.357800   \n",
       "PCTFLOAN      6849.0     0.522211       0.283616    0.0    0.332900   \n",
       "UG25ABV       6718.0     0.410021       0.228939    0.0    0.241500   \n",
       "\n",
       "                    50%          75%           max  \n",
       "HBCU            0.00000     0.000000  1.000000e+00  \n",
       "MENONLY         0.00000     0.000000  1.000000e+00  \n",
       "WOMENONLY       0.00000     0.000000  1.000000e+00  \n",
       "RELAFFIL        0.00000     0.000000  1.000000e+00  \n",
       "SATVRMID      510.00000   555.000000  7.650000e+02  \n",
       "SATMTMID      520.00000   565.000000  7.850000e+02  \n",
       "DISTANCEONLY    0.00000     0.000000  1.000000e+00  \n",
       "UGDS          412.50000  1929.500000  1.515580e+05  \n",
       "UGDS_WHITE      0.55570     0.747875  1.000000e+00  \n",
       "UGDS_BLACK      0.10005     0.257700  1.000000e+00  \n",
       "UGDS_HISP       0.07140     0.198875  1.000000e+00  \n",
       "UGDS_ASIAN      0.01290     0.032700  9.727000e-01  \n",
       "UGDS_AIAN       0.00260     0.007300  1.000000e+00  \n",
       "UGDS_NHPI       0.00000     0.002500  9.983000e-01  \n",
       "UGDS_2MOR       0.01750     0.033900  5.333000e-01  \n",
       "UGDS_NRA        0.00000     0.011700  9.286000e-01  \n",
       "UGDS_UNKN       0.01430     0.045400  9.027000e-01  \n",
       "PPTUG_EF        0.15040     0.376900  1.000000e+00  \n",
       "CURROPER        1.00000     1.000000  1.000000e+07  \n",
       "PCTPELL         0.52150     0.712900  1.000000e+00  \n",
       "PCTFLOAN        0.58330     0.745000  1.000000e+00  \n",
       "UG25ABV         0.40075     0.572275  1.000000e+00  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.describe(include=['number']).T  # also works as the default int/float are 64 bits"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "college['MENONLY'] = college['MENONLY'].astype('float16')\n",
    "college['RELAFFIL'] = college['RELAFFIL'].astype('int8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "60280"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college.index = pd.Int64Index(college.index)\n",
    "college.index.memory_usage()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting the smallest of the largest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Avatar</td>\n",
       "      <td>7.9</td>\n",
       "      <td>237000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Pirates of the Caribbean: At World's End</td>\n",
       "      <td>7.1</td>\n",
       "      <td>300000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Spectre</td>\n",
       "      <td>6.8</td>\n",
       "      <td>245000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>8.5</td>\n",
       "      <td>250000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Star Wars: Episode VII - The Force Awakens</td>\n",
       "      <td>7.1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  movie_title  imdb_score       budget\n",
       "0                                      Avatar         7.9  237000000.0\n",
       "1    Pirates of the Caribbean: At World's End         7.1  300000000.0\n",
       "2                                     Spectre         6.8  245000000.0\n",
       "3                       The Dark Knight Rises         8.5  250000000.0\n",
       "4  Star Wars: Episode VII - The Force Awakens         7.1          NaN"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie2 = movie[['movie_title', 'imdb_score', 'budget']]\n",
    "movie2.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2725</th>\n",
       "      <td>Towering Inferno</td>\n",
       "      <td>9.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1920</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>9.3</td>\n",
       "      <td>25000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3402</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>9.2</td>\n",
       "      <td>6000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2779</th>\n",
       "      <td>Dekalog</td>\n",
       "      <td>9.1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4312</th>\n",
       "      <td>Kickboxer: Vengeance</td>\n",
       "      <td>9.1</td>\n",
       "      <td>17000000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   movie_title  imdb_score      budget\n",
       "2725          Towering Inferno         9.5         NaN\n",
       "1920  The Shawshank Redemption         9.3  25000000.0\n",
       "3402             The Godfather         9.2   6000000.0\n",
       "2779                   Dekalog         9.1         NaN\n",
       "4312      Kickboxer: Vengeance         9.1  17000000.0"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.nlargest(100, 'imdb_score').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>Butterfly Girl</td>\n",
       "      <td>8.7</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4801</th>\n",
       "      <td>Children of Heaven</td>\n",
       "      <td>8.5</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4706</th>\n",
       "      <td>12 Angry Men</td>\n",
       "      <td>8.9</td>\n",
       "      <td>350000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4550</th>\n",
       "      <td>A Separation</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4636</th>\n",
       "      <td>The Other Dream Team</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               movie_title  imdb_score    budget\n",
       "4804        Butterfly Girl         8.7  180000.0\n",
       "4801    Children of Heaven         8.5  180000.0\n",
       "4706          12 Angry Men         8.9  350000.0\n",
       "4550          A Separation         8.4  500000.0\n",
       "4636  The Other Dream Team         8.4  500000.0"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.nlargest(100, 'imdb_score').nsmallest(5, 'budget')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Selecting the largest of each group by sorting"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie2 = movie[['movie_title', 'title_year', 'imdb_score']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>title_year</th>\n",
       "      <th>imdb_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3884</th>\n",
       "      <td>The Veil</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>4.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2375</th>\n",
       "      <td>My Big Fat Greek Wedding 2</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>6.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2794</th>\n",
       "      <td>Miracles from Heaven</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>6.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>Independence Day: Resurgence</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>5.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>153</th>\n",
       "      <td>Kung Fu Panda 3</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>7.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       movie_title  title_year  imdb_score\n",
       "3884                      The Veil      2016.0         4.7\n",
       "2375    My Big Fat Greek Wedding 2      2016.0         6.1\n",
       "2794          Miracles from Heaven      2016.0         6.8\n",
       "92    Independence Day: Resurgence      2016.0         5.5\n",
       "153                Kung Fu Panda 3      2016.0         7.2"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.sort_values('title_year', ascending=False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>title_year</th>\n",
       "      <th>imdb_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4312</th>\n",
       "      <td>Kickboxer: Vengeance</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>9.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4277</th>\n",
       "      <td>A Beginner's Guide to Snuff</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3798</th>\n",
       "      <td>Airlift</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Captain America: Civil War</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>Godzilla Resurgence</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>8.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      movie_title  title_year  imdb_score\n",
       "4312         Kickboxer: Vengeance      2016.0         9.1\n",
       "4277  A Beginner's Guide to Snuff      2016.0         8.7\n",
       "3798                      Airlift      2016.0         8.5\n",
       "27     Captain America: Civil War      2016.0         8.2\n",
       "98            Godzilla Resurgence      2016.0         8.2"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie3 = movie2.sort_values(['title_year','imdb_score'], ascending=False)\n",
    "movie3.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>title_year</th>\n",
       "      <th>imdb_score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4312</th>\n",
       "      <td>Kickboxer: Vengeance</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>9.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3745</th>\n",
       "      <td>Running Forever</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>8.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4369</th>\n",
       "      <td>Queen of the Mountains</td>\n",
       "      <td>2014.0</td>\n",
       "      <td>8.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3935</th>\n",
       "      <td>Batman: The Dark Knight Returns, Part 2</td>\n",
       "      <td>2013.0</td>\n",
       "      <td>8.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>8.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  movie_title  title_year  imdb_score\n",
       "4312                     Kickboxer: Vengeance      2016.0         9.1\n",
       "3745                          Running Forever      2015.0         8.6\n",
       "4369                   Queen of the Mountains      2014.0         8.7\n",
       "3935  Batman: The Dark Knight Returns, Part 2      2013.0         8.4\n",
       "3                       The Dark Knight Rises      2012.0         8.5"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie_top_year = movie3.drop_duplicates(subset='title_year')\n",
    "movie_top_year.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>title_year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4026</th>\n",
       "      <td>Compadres</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>R</td>\n",
       "      <td>3000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4658</th>\n",
       "      <td>Fight to the Finish</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>150000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4661</th>\n",
       "      <td>Rodeo Girl</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>PG</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3252</th>\n",
       "      <td>The Wailing</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>Not Rated</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4659</th>\n",
       "      <td>Alleluia! The Devil's Carnival</td>\n",
       "      <td>2016.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4731</th>\n",
       "      <td>Bizarre</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>Unrated</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>812</th>\n",
       "      <td>The Ridiculous 6</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>TV-14</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4831</th>\n",
       "      <td>The Gallows</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>R</td>\n",
       "      <td>100000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4825</th>\n",
       "      <td>Romantic Schemer</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>125000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3796</th>\n",
       "      <td>R.L. Stine's Monsterville: The Cabinet of Souls</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>PG</td>\n",
       "      <td>4400000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                          movie_title  title_year  \\\n",
       "4026                                        Compadres      2016.0   \n",
       "4658                              Fight to the Finish      2016.0   \n",
       "4661                                       Rodeo Girl      2016.0   \n",
       "3252                                      The Wailing      2016.0   \n",
       "4659                   Alleluia! The Devil's Carnival      2016.0   \n",
       "4731                                          Bizarre      2015.0   \n",
       "812                                  The Ridiculous 6      2015.0   \n",
       "4831                                      The Gallows      2015.0   \n",
       "4825                                 Romantic Schemer      2015.0   \n",
       "3796  R.L. Stine's Monsterville: The Cabinet of Souls      2015.0   \n",
       "\n",
       "     content_rating     budget  \n",
       "4026              R  3000000.0  \n",
       "4658          PG-13   150000.0  \n",
       "4661             PG   500000.0  \n",
       "3252      Not Rated        NaN  \n",
       "4659            NaN   500000.0  \n",
       "4731        Unrated   500000.0  \n",
       "812           TV-14        NaN  \n",
       "4831              R   100000.0  \n",
       "4825          PG-13   125000.0  \n",
       "3796             PG  4400000.0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie4 = movie[['movie_title', 'title_year', 'content_rating', 'budget']]\n",
    "movie4_sorted = movie4.sort_values(['title_year', 'content_rating', 'budget'], \n",
    "                                   ascending=[False, False, True])\n",
    "movie4_sorted.drop_duplicates(subset=['title_year', 'content_rating']).head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Replicating nlargest with sort_values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>Butterfly Girl</td>\n",
       "      <td>8.7</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4801</th>\n",
       "      <td>Children of Heaven</td>\n",
       "      <td>8.5</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4706</th>\n",
       "      <td>12 Angry Men</td>\n",
       "      <td>8.9</td>\n",
       "      <td>350000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4550</th>\n",
       "      <td>A Separation</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4636</th>\n",
       "      <td>The Other Dream Team</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               movie_title  imdb_score    budget\n",
       "4804        Butterfly Girl         8.7  180000.0\n",
       "4801    Children of Heaven         8.5  180000.0\n",
       "4706          12 Angry Men         8.9  350000.0\n",
       "4550          A Separation         8.4  500000.0\n",
       "4636  The Other Dream Team         8.4  500000.0"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie2 = movie[['movie_title', 'imdb_score', 'budget']]\n",
    "movie_smallest_largest = movie2.nlargest(100, 'imdb_score').nsmallest(5, 'budget')\n",
    "movie_smallest_largest"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2725</th>\n",
       "      <td>Towering Inferno</td>\n",
       "      <td>9.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1920</th>\n",
       "      <td>The Shawshank Redemption</td>\n",
       "      <td>9.3</td>\n",
       "      <td>25000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3402</th>\n",
       "      <td>The Godfather</td>\n",
       "      <td>9.2</td>\n",
       "      <td>6000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2779</th>\n",
       "      <td>Dekalog</td>\n",
       "      <td>9.1</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4312</th>\n",
       "      <td>Kickboxer: Vengeance</td>\n",
       "      <td>9.1</td>\n",
       "      <td>17000000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   movie_title  imdb_score      budget\n",
       "2725          Towering Inferno         9.5         NaN\n",
       "1920  The Shawshank Redemption         9.3  25000000.0\n",
       "3402             The Godfather         9.2   6000000.0\n",
       "2779                   Dekalog         9.1         NaN\n",
       "4312      Kickboxer: Vengeance         9.1  17000000.0"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.sort_values('imdb_score', ascending=False).head(100).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4815</th>\n",
       "      <td>A Charlie Brown Christmas</td>\n",
       "      <td>8.4</td>\n",
       "      <td>150000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4801</th>\n",
       "      <td>Children of Heaven</td>\n",
       "      <td>8.5</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4804</th>\n",
       "      <td>Butterfly Girl</td>\n",
       "      <td>8.7</td>\n",
       "      <td>180000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4706</th>\n",
       "      <td>12 Angry Men</td>\n",
       "      <td>8.9</td>\n",
       "      <td>350000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4636</th>\n",
       "      <td>The Other Dream Team</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    movie_title  imdb_score    budget\n",
       "4815  A Charlie Brown Christmas         8.4  150000.0\n",
       "4801         Children of Heaven         8.5  180000.0\n",
       "4804             Butterfly Girl         8.7  180000.0\n",
       "4706               12 Angry Men         8.9  350000.0\n",
       "4636       The Other Dream Team         8.4  500000.0"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.sort_values('imdb_score', ascending=False).head(100).sort_values('budget').head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4023</th>\n",
       "      <td>Oldboy</td>\n",
       "      <td>8.4</td>\n",
       "      <td>3000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4163</th>\n",
       "      <td>To Kill a Mockingbird</td>\n",
       "      <td>8.4</td>\n",
       "      <td>2000000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4395</th>\n",
       "      <td>Reservoir Dogs</td>\n",
       "      <td>8.4</td>\n",
       "      <td>1200000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4550</th>\n",
       "      <td>A Separation</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4636</th>\n",
       "      <td>The Other Dream Team</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                movie_title  imdb_score     budget\n",
       "4023                 Oldboy         8.4  3000000.0\n",
       "4163  To Kill a Mockingbird         8.4  2000000.0\n",
       "4395         Reservoir Dogs         8.4  1200000.0\n",
       "4550           A Separation         8.4   500000.0\n",
       "4636   The Other Dream Team         8.4   500000.0"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.nlargest(100, 'imdb_score').tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>budget</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3799</th>\n",
       "      <td>Anne of Green Gables</td>\n",
       "      <td>8.4</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3777</th>\n",
       "      <td>Requiem for a Dream</td>\n",
       "      <td>8.4</td>\n",
       "      <td>4500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3935</th>\n",
       "      <td>Batman: The Dark Knight Returns, Part 2</td>\n",
       "      <td>8.4</td>\n",
       "      <td>3500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4636</th>\n",
       "      <td>The Other Dream Team</td>\n",
       "      <td>8.4</td>\n",
       "      <td>500000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2455</th>\n",
       "      <td>Aliens</td>\n",
       "      <td>8.4</td>\n",
       "      <td>18500000.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  movie_title  imdb_score      budget\n",
       "3799                     Anne of Green Gables         8.4         NaN\n",
       "3777                      Requiem for a Dream         8.4   4500000.0\n",
       "3935  Batman: The Dark Knight Returns, Part 2         8.4   3500000.0\n",
       "4636                     The Other Dream Team         8.4    500000.0\n",
       "2455                                   Aliens         8.4  18500000.0"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2.sort_values('imdb_score', ascending=False).head(100).tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Calculating a trailing stop order price"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas_datareader as pdr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Note: pandas_datareader issues\n",
    "pandas_datareader can have issues when the source is 'google'. It can also read from Yahoo! finance. Try switching it to 'yahoo'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-01-03</th>\n",
       "      <td>214.860001</td>\n",
       "      <td>220.330002</td>\n",
       "      <td>210.960007</td>\n",
       "      <td>216.990005</td>\n",
       "      <td>216.990005</td>\n",
       "      <td>5923300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-04</th>\n",
       "      <td>214.750000</td>\n",
       "      <td>228.000000</td>\n",
       "      <td>214.309998</td>\n",
       "      <td>226.990005</td>\n",
       "      <td>226.990005</td>\n",
       "      <td>11213500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-05</th>\n",
       "      <td>226.419998</td>\n",
       "      <td>227.479996</td>\n",
       "      <td>221.949997</td>\n",
       "      <td>226.750000</td>\n",
       "      <td>226.750000</td>\n",
       "      <td>5911700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-06</th>\n",
       "      <td>226.929993</td>\n",
       "      <td>230.309998</td>\n",
       "      <td>225.449997</td>\n",
       "      <td>229.009995</td>\n",
       "      <td>229.009995</td>\n",
       "      <td>5527900</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-09</th>\n",
       "      <td>228.970001</td>\n",
       "      <td>231.919998</td>\n",
       "      <td>228.000000</td>\n",
       "      <td>231.279999</td>\n",
       "      <td>231.279999</td>\n",
       "      <td>3957000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-10</th>\n",
       "      <td>232.000000</td>\n",
       "      <td>232.000000</td>\n",
       "      <td>226.889999</td>\n",
       "      <td>229.869995</td>\n",
       "      <td>229.869995</td>\n",
       "      <td>3660000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-11</th>\n",
       "      <td>229.070007</td>\n",
       "      <td>229.979996</td>\n",
       "      <td>226.679993</td>\n",
       "      <td>229.729996</td>\n",
       "      <td>229.729996</td>\n",
       "      <td>3650800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-01-12</th>\n",
       "      <td>229.059998</td>\n",
       "      <td>230.699997</td>\n",
       "      <td>225.580002</td>\n",
       "      <td>229.589996</td>\n",
       "      <td>229.589996</td>\n",
       "      <td>3790200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Open        High         Low       Close   Adj Close  \\\n",
       "Date                                                                     \n",
       "2017-01-03  214.860001  220.330002  210.960007  216.990005  216.990005   \n",
       "2017-01-04  214.750000  228.000000  214.309998  226.990005  226.990005   \n",
       "2017-01-05  226.419998  227.479996  221.949997  226.750000  226.750000   \n",
       "2017-01-06  226.929993  230.309998  225.449997  229.009995  229.009995   \n",
       "2017-01-09  228.970001  231.919998  228.000000  231.279999  231.279999   \n",
       "2017-01-10  232.000000  232.000000  226.889999  229.869995  229.869995   \n",
       "2017-01-11  229.070007  229.979996  226.679993  229.729996  229.729996   \n",
       "2017-01-12  229.059998  230.699997  225.580002  229.589996  229.589996   \n",
       "\n",
       "              Volume  \n",
       "Date                  \n",
       "2017-01-03   5923300  \n",
       "2017-01-04  11213500  \n",
       "2017-01-05   5911700  \n",
       "2017-01-06   5527900  \n",
       "2017-01-09   3957000  \n",
       "2017-01-10   3660000  \n",
       "2017-01-11   3650800  \n",
       "2017-01-12   3790200  "
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tsla = pdr.DataReader('tsla', data_source='yahoo',start='2017-1-1')\n",
    "tsla.head(8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "tsla_close = tsla['Close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2017-01-03    216.990005\n",
       "2017-01-04    226.990005\n",
       "2017-01-05    226.990005\n",
       "2017-01-06    229.009995\n",
       "2017-01-09    231.279999\n",
       "2017-01-10    231.279999\n",
       "2017-01-11    231.279999\n",
       "2017-01-12    231.279999\n",
       "Name: Close, dtype: float64"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tsla_cummax = tsla_close.cummax()\n",
    "tsla_cummax.head(8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2017-01-03    195.291004\n",
       "2017-01-04    204.291004\n",
       "2017-01-05    204.291004\n",
       "2017-01-06    206.108996\n",
       "2017-01-09    208.151999\n",
       "2017-01-10    208.151999\n",
       "2017-01-11    208.151999\n",
       "2017-01-12    208.151999\n",
       "Name: Close, dtype: float64"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tsla_trailing_stop = tsla_cummax * .9\n",
    "tsla_trailing_stop.head(8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## There's more..."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def set_trailing_loss(symbol, purchase_date, perc):\n",
    "    close = pdr.DataReader(symbol, 'yahoo', start=purchase_date)['Close']\n",
    "    return close.cummax() * perc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date\n",
       "2017-06-01    59.584998\n",
       "2017-06-02    60.996002\n",
       "2017-06-05    61.437999\n",
       "2017-06-06    61.641997\n",
       "2017-06-07    61.641997\n",
       "Name: Close, dtype: float64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "msft_trailing_stop = set_trailing_loss('msft', '2017-6-1', .85)\n",
    "msft_trailing_stop.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
